#include <iostream>
#include <stack>
using namespace std;
int main(){
    stack<int> s1;
    stack<int> s2;
    int a,b;
    cin>>a>>b;
    if(a>b){
        int m;
        m=a;
        a=b;
        b=m;
    }
    char c;
    cin>>c;
    while(c!='T'){
        int flag =0;
        int y;
        if(c=='A'){
            cin>>y;
            if(s1.size()==a&&s2.empty()){
                while(s1.size()>0){
                    s2.push(s1.top());
                    s1.pop();
                }
                flag=1;
            }
            if(s1.size()<a){
                s1.push(y);
                flag=1;
            }
            if(!flag){cout<<"ERROR:Full"<<endl;}
        }else{
            int flag1=0;
            if(!s2.empty()){cout<<s2.top()<<endl;s2.pop();flag1=1;}
            else if(s2.empty()&&!s1.empty()){
                while(s1.size()>0){
                    s2.push(s1.top());
                    s1.pop();
                }
                cout<<s2.top()<<endl;s2.pop();flag1=1;
            }
            if(!flag1){cout<<"ERROR:Empty"<<endl;}
        }
        cin>>c;
    }
}
